package com.yyw.controller.scurity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.List;

/**
 * @ClassName UserDatilServiceImpl
 * @Description TODO
 * @Author YiYuWei
 * @Date 2020/7/1 23:26
 * @Version 1.0
 */
public class UserDatilServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 模拟数据库操作
        List<GrantedAuthority> authorityList = AuthorityUtils.createAuthorityList("ROLE_user");
        if (!username.equals("user")){
            throw new UsernameNotFoundException("用户名不存在");
        }

        return new User(username,"123456", authorityList);

    }
}
